// Line class - line element for scene - draws and manages a line in the scene
ResponsiveIrregularShapePainter.prototype = new ShapePainter();  
ResponsiveIrregularShapePainter.prototype.constructor=ResponsiveIrregularShapePainter;
function ResponsiveIrregularShapePainter(scene){
	this.scene = scene;
	this.shape = null;
	this.tempLine = null;	

	this.createShape = function(pos){		
		if(!this.scene)return;			
		this.shape = new ResponsiveIrregularShape([]);			
		this.shape.strokeWidth = 3;
		this.shape.strokeColor = "#00f";						
		this.shape.fill=true;
		this.shape.fillColor = "#0066FF";
		this.shape.addPoint({x:pos.x,y:pos.y});
		this.scene.add(this.shape);
		
		this.tempLine = new ResponsiveLine(0,0,0,0);
		this.tempLine.percentagePosition.x = 0;
		this.tempLine.percentagePosition.y = 0;		
		this.tempLine.percentagePosition.w = 0;
		this.tempLine.percentagePosition.h = 0;
		this.tempLine.strokeColor = "#f00";
		this.tempLine.strokeWidth = 3;
		this.scene.add(this.tempLine);
	}
	this.createShapeCheckpoint = function(pos){
		if(this.shape==null){
			this.createShape(pos);
			return;
		}		
		var newPoint = pos;
		this.shape.addPoint(newPoint);		
		
		// hide temp line for now
		this.tempLine.percentagePosition.x = newPoint.x;
		this.tempLine.percentagePosition.y = newPoint.y;		
		this.tempLine.percentagePosition.w = 0;
		this.tempLine.percentagePosition.h = 0;		
		this.tempLine.updateRectangle();		
		
		// show the new point on the building shape
		this.shape.updateIrregularShape();
		this.scene.invalidate();
	}
	this.createShapeProgress = function(pos){
		if(this.shape){			
			var point = this.shape.percentagePoints[this.shape.percentagePoints.length-1];
			
			this.tempLine.percentagePosition.x = point.x;
			this.tempLine.percentagePosition.y = point.y;
			
			this.tempLine.percentagePosition.w = pos.x - point.x;
			this.tempLine.percentagePosition.h = pos.y - point.y;			
			this.tempLine.updateRectangle();
			console.log(JSON.stringify(this.tempLine.percentagePosition));
			this.scene.invalidate();
		}
		else {
			console.log("shape is null");
		}
	}
	this.finalize = function(){			
		if(this.shape){
			this.shape.painter = this;			
			this.scene.remove(this.tempLine);										
			this.scene.invalidate();
		}
	}
	
	this.serialize = function(){
		return "new ResponsiveIrregularShape("+JSON.stringify(this.shape.percentagePoints)+")";
	}
}
